#!/usr/bin/env python



import time
from src.util import util
from src.cash_trade import CashTrade
from binance.client import Client
# config = util.open('src/config/test.json')
config = util.open('src/config/product.json')
if __name__ == '__main__':
    delayTime = 30
    cashTrade = CashTrade(config)
    while True:
        # time.time()获取时间为秒
        startTime = time.time()
        try:
            cashTrade.exchange('ETHUSDT', interval=Client.KLINE_INTERVAL_1MINUTE)
        except Exception as e:
            print('error %s' % e)

        # 如果延时时间大于执行方法时间，则以减去执行方法时间，否则不做延时，
        # 即已经超过了设定延时，则立即执行下一次循环
        diffTime = int(time.time() - startTime)
        if delayTime > diffTime:
            time.sleep(delayTime - diffTime)


